<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\ocean;

use app\enum\OeCodeEnum;
use app\enum\OeUrlEnum;
use app\service\BaseService;
use proxy\Client;
use think\Exception;

class AdvertiserService extends BaseService
{
    /**
     * 获取账户信息.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getAccountInfo(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'advertiser_info');

            return $client->getJson($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 查询应用分包列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getAppExtend(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'app_extend_list');

            $res = $client->getJson($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 查询抖音列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getAwemeList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'app_aweme_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取可用优化目标（巨量广告升级版）.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getOptimizedGoal(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'optimized_goal_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取可用深度优化方式（广告投放升级版）.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getDeepBidType(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'deep_bid_get');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取账户下原生锚点.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getNativeAnchor(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'native_anchor_get');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 查询抖音主页视频.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getAwemeVideo(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'app_aweme_video');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    public static function createProject(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('ad');
            $serviceUrl = OeUrlEnum::getServiceUrl('ad', 'project_create');
            $res = $client->postJson($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 通过优化目标获取橙子落地页站点信息.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getOrangeSite(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'orange_site');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取项目列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getProjectList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'project_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取广告列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getPromotionList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'promotion_list');
            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取广告主数据列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getAccount(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'account_report');
            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取广告组数据列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getCampaign(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'campaign_report');
            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取广告计划数据列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getUnit(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'unit_report');
            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取商品库信息.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getProductPlatform(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'product_platform');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取商品列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getProductList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'product_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    public static function getClueProductList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('ad');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'clue_product_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取视频列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getVideoList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'video_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取视频封面.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getVideoCover(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'video_cover');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取低效素材.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getEfficiencyVideoList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'video_efficiency_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取素材标签列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getVideoTagList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'video_tag_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取定向包.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getAudiencePackage(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'audience_package');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取无效素材列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getRebateMaterialList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'rebate_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取可用优化目标（巨量广告升级版）.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getAssets(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'assets_list');
            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取事件资产下的监测链接组.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getTrackUrl(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('advertiser');
            $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'track_url');
            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (intval($res['code']) != OeCodeEnum::SUCCESS) {
                return self::setError($res['message']);
            }

            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 获取白名单能力.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string|
     * @throws Exception
     */
    public static function getToolsGray(array $headers = [], array $params = [])
    {
        $client = new Client();
        $serviceName = OeUrlEnum::getServiceName('advertiser');
        $serviceUrl = OeUrlEnum::getServiceUrl('advertiser', 'tools_gray');
        $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
        if (intval($res['code']) != OeCodeEnum::SUCCESS) {
            return self::setError($res['message']);
        }

        return $res;
    }
}
